<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <link rel="stylesheet" type="text/css" href="__STATIC__/index/css/style.css"/>
    <script type="text/javascript" src="__STATIC__/index/js/rem.js"></script>
    <title>确认订单</title>
    <style>
        .x-disabled {
            pointer-events: none;
            cursor: default;
            opacity: 0.6;
        }
    </style>

</head>
<body class="geryBg">
<div class="order">
    <!--地址管理-->
    <div class="order_address">
        <a href="/index/cart/addrList">
            <div class="order_add_detail">
                <input type="hidden" name="name" value="">
                <input type="hidden" name="phone" value="">
                <input type="hidden" name="address" value="">
                <div class="clear order_concat order_confirm_concat smoth">
                    <p class="fl">收货人: <em id="name"></em></p>
                    <p class="fr" id="phone"></p>
                </div>
                <div class="order_add order_confirm_concat">
                    <img class="icon-add" src="__STATIC__/index/img/icon-add.png"/>
                    <p class="normall-text smoth">收货地址: <em id="address"> <i class="order_default">默认</i></em>
                    </p>
                    <img class="icon-arrow" src="__STATIC__/index/img/arrow-gery.png"/>
                </div>
            </div>
        </a>
        <p class="line"></p>
    </div>

    <!--商品详情-->
    {foreach $list as $k=>$vo}
    <div class="order_goods clear">
        <input type="hidden" name="ids[{$k}][id]" value="{$vo.mgl_id}">
        <input type="hidden" name="ids[{$k}][num]" value="{$vo.num}">
        <input type="hidden" name="ids[{$k}][mg_id]" value="{$vo.mg_id}">
        <div class="order_img fl">
            <img class="auto-img" src="{$vo.goods_spec_img}"/>
        </div>
        <div class="order_des fr">
            <!--商品名-->
            <div class="clear super-text smoth bold">
                <p class="fl">{$vo.goods_title}</p>
            </div>
            <!--商品分类-->
            <div class="clear normall-text lightgery">
                <p class="fl">{$vo.goods_spec}</p>
            </div>
            <div class="clear order_price">
                <p class="fl brown super-text single_price">￥{$vo.price}</p>
                <p class="fr small-text smoth good_num">X{$vo.num}</p>
            </div>
        </div>
    </div>
    {/foreach}

    <!--商品合计以及运费-->
    <div class="order_account whiteBg">
        <div class="order_money clear super-text bold">
            <p class="fl smoth">商品合计</p>
            <p class="fr brown single_good">￥{$sum}</p>
        </div>
        <!--<div class="clear smoth super-text order_carrige bold">-->
            <!--<p class="fl">运费</p>-->
            <!--<p class="fr single_carr">￥0.00</p>-->
        <!--</div>-->
        <!--积分兑换-->
        <div class="clear order_integral">
            <div class="fl super-text has_check">
                <i class="check"></i>
                <span class="smoth bold">{$point}积分抵扣</span>
                <span class="lightgery">(剩余{$jifen}积分)</span>
            </div>
            <p class="fr smoth super-text bold">-￥{$point_pay}</p>
        </div>
    </div>

    <!--积分兑换规则-->
    <div class="order_rule">
        <p class="normall-text lightgery">积分规则：{:conf('jifenone_l')}积分可抵扣￥{:conf('jifenone_r')}</p>
    </div>

    <!--提交按钮-->
    <div class="order_btn whiteBg order_confirm_btn">
        <div class="fr order_confirm_btn_des">
            <span class="smoth super-text">应付:</span>
            <span class="brown money">￥{$sum}</span>
            <!--原价-->
            <input type="hidden" name="amount" value="{$sum}">
            <!--积分-->
            <input type="hidden" name="point" value="0">
            <!--积分抵扣金额-->
            <input type="hidden" name="point_pay" value="0">
            <!--是否有积分支付，2否-->
            <input type="hidden" name="is_point" value="2">
            <!--实付-->
            <input type="hidden" name="pay" value="{$sum}">

            <a class="confirm_order" href="javascript:;">提交订单</a>
        </div>
    </div>
</div>
<script type="text/javascript" src="__STATIC__/index/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="__STATIC__/index/js/layer/mobile/layer.js"></script>
<script type="text/javascript">
    $('.order_integral .has_check .check').on('click', function () {
        $(this).toggleClass('checked');
        //总价
        var sum = parseInt('{$sum}');
        //积分
        var point = parseInt('{$point}');
        //积分金额
        var point_pay = parseInt('{$point_pay}');

        if ($(this).hasClass('checked')) {
            var pay = sum - point_pay;
            $('.money').text('￥' + pay.toFixed(2));
            $('input[name="pay"]').val(pay);
            $('input[name="is_point"]').val('1');
            $('input[name="point"]').val(point);
            $('input[name="point_pay"]').val(point_pay);
        } else {
            $('.money').text('￥' + sum.toFixed(2));
            $('input[name="pay"]').val(sum);
            $('input[name="is_point"]').val('2');
            $('input[name="point"]').val('0');
            $('input[name="point_pay"]').val('0');
        }
    });


    //提交订单
    $('.order_confirm_btn_des a').on('click', function () {
        var id = $('input').serializeArray();
        $(this).addClass('x-disabled');
        $.ajax({
            url:"/index/order/make",
            type:"post",
            data:id,
            success:function (res) {
                if(res.code=='success'){
                    window.location.replace('/index/order/detail?id='+res.order_id);
                    // window.location.href='/index/order/detail?id='+res.order_id;
                }else {
                    layer.open({
                        content: res.msg,
                        skin: 'msg',
                        time: 2
                    })
                }
            }
        })

    })

    window.onpageshow = function () {
        var aid = sessionStorage.getItem('aid');
        $.ajax({
            url:'addr_ajax',
            type:'post',
            data:{id:aid},
            success:function (res) {
                if (res.code=='110'){
                    $('.order_add_detail').html("<p style='text-align: center;font-size: 25px'>请选择地址</p>");
                }else{
                    $('#name').text(res.data.name);
                    $('input[name="name"]').val(res.data.name);
                    $('#phone').text(res.data.phone);
                    $('input[name="phone"]').val(res.data.phone);
                    $('#address').html(res.data.address);
                    $('input[name="address"]').val(res.data.addressx);
                }

            }
        })
    }
</script>
</body>
</html>